<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{_fragment :: head(title='新增博客')}">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width initial-scale=1.0">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css" th:href="@{/css/me.css}">
    <link rel="stylesheet" href="../../static/editormd/css/editormd.css" th:href="@{/editormd/css/editormd.css}">
    <title>新增博客</title>
</head>
<body>


<!--导航-->
<nav class="ui inverted attached segment" th:replace="~{_fragment :: nav(n=2)}">
    <div class="ui container">
        <div class="ui inverted menu secondary">
            <!--            item表示是menu中的单位之一-->
            <h2 class="ui teal header item">
                WANT
            </h2>
            <a href="#" class="ui item"><i class="info icon"></i>博客列表</a>
            <a href="#" class="ui item active"><i class="home icon"></i>博客</a>
            <a href="#" class="ui item"><i class="idea icon"></i>分类</a>
            <a href="#" class="ui item"><i class="tags icon"></i>标签</a>

            <div class="item right">
                <div class="ui input transparent inverted">
                    <input type="text" placeholder="搜索...">
                    <i class="search icon link"></i>
                </div>
            </div>
        </div>
    </div>

</nav>

<!--内容-->
<br>

<!--<div class="ui right aligned container">-->
<!--    <a href="" th:href="@{}" class="ui positive button"><i class="folder icon"></i>草稿箱</a>-->
<!--</div>-->
<br>
<br>
<div>

    <div class="ui container" >
        <form th:action="@{/admin/inOrupBlog}" method="post" th:id="blog-form" th:object="${blog}"  class="ui form">
            <input type="hidden" name="published" th:value="*{published}"> <!--发布状态-->
            <input type="hidden" name="id" th:value="*{id}">

            <div class="required field">
                <div class="ui left labeled input">
                    <!-- 下拉label-->
                    <div class="ui dropdown label teal basic">
                        <input type="hidden" th:value="*{flag}" name="flag">
                        <div class="text">原创</div>
                        <i class="dropdown icon"></i>
                        <div class="menu">
                            <div class="item">原创</div>
                            <div class="item">转载</div>
                        </div>
                    </div>
                    <input type="text" name="title" placeholder="标题" th:value="*{title}">
                </div>
            </div>

            <div class="required field">
                <div id="md-content" style="z-index: 1 !important;">
                    <textarea name="content" maxlength="300" placeholder="博客内容...." th:text="*{content}"></textarea>
                </div>
            </div>

            <!--            分类-->
            <div class="two field">
                <div class="required field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">分类</label>

                        <div class="ui fluid selection dropdown">
                            <input type="hidden" name="type.id" th:value="*{type}!= null ? *{type.id}:null">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div class="item" th:each="type:${types}" th:text="${type.name}" th:data-value="${type.id}"></div>
                            </div>
                        </div>

                    </div>
                </div>

                <div class="required field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">标签</label>
                        <div class="ui fluid selection multiple search dropdown">
                            <input type="hidden" name="tagids" th:value="*{tagids}">
                            <i class="dropdown icon"></i>
                            <div class="text">标签</div>
                            <div class="menu">
                                <div class="item" data-value="1" th:each="tag:${tags}" th:data-value="${tag.id}" th:text="${tag.name}">xxx</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!--            图片-->
            <div class="required field">
                <div class="ui left labeled input">
                    <label class="ui label teal basic">首图</label>
                    <input type="text" name="firstPicture" th:value="*{firstPicture}" placeholder="首图">
                </div>
            </div>


            <div class="required field">

                <div class="ui checkbox">
                    <input type="checkbox" id="shareStatement" name="shareStatement" th:checked="*{shareStatement}">
                    <label for="shareStatement">转载声明</label>
                </div>
            </div>


            <div class="required field">
                <div class="ui checkbox">
                    <input type="checkbox" id="recommend" name="recommend" th:checked="*{recommend}">
                    <label for="recommend">推荐</label>
                </div>
            </div>

            <div class="required field">
                <div class="ui checkbox">
                    <input type="checkbox" id="commentabled" name="commentabled" th:checked="*{commentabled}">
                    <label for="commentabled">开启评论</label>
                </div>
            </div>


            <!--验证表单时在此处显示-->
            <div class="ui error message"></div>


            <div class="ui right aligned container">
                <button class="ui button" type="button" onclick="window.history.go(-1)">返回</button>
                <button class="ui button" type="button" th:id="save-btn">保存</button>
                <button class="ui button" type="button" th:id="publish-btn">发布</button>
            </div>
        </form>
<!--        <th:block th:if="${blog}!=null">-->
<!--            -->
<!--        </th:block>-->


    </div>
</div>
<br>
<br>
<br>
<!--footer-->


<footer th:replace="~{_fragment :: footer}" class="ui inverted vertical segment">

    <div class="ui center aligned container m-padded-tb-massive">
        <!--        grid将footer分为16-->
        <div class="ui grid divided inverted">
            <!--            wide填满-->
            <div class="three wide column">
                <img src="../../static/images/weichat.png" th:src="/images/weichat.png" class="image ui rounded" style="width:110px;height:110px">
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <div class="ui inverted link list " >
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <p>这里是一些其他信息</p>
            </div>


        </div>

        <div class="ui inverted section divider"></div>
        <p>关于法律信息</p>
    </div>
</footer>

<th:block th:replace="~{_fragment :: script}">
</th:block>
<script type="text/javascript">

    //初始化Markdown编辑器
    var contentEditor;
    $(function() {
        contentEditor = editormd("md-content", {
            width   : "100%",
            height  : 500,
            syncScrolling : "single",
            path    : "/editormd/lib/"
        });
    });

    $('.ui.dropdown').dropdown({
        on : 'hover'
    });


    $('#save-btn').click(function () {
        $('[name="published"]').val(false);
        $('#blog-form').submit();
    })

    $('#publish-btn').click(function () {
        $('[name="published"]').val(true);
        $('#blog-form').submit();
    })


    $('.ui.form').form({    //表单元素非空验证
        fields : {
            title : {
                identifier: 'title',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客标题'
                }]
            },
            content : {
                identifier: 'content',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客内容'
                }]
            },
            typeId : {
                identifier: 'type.id',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客分类'
                }]
            },
            firstPicture : {
                identifier: 'firstPicture',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客首图'
                }]
            },
            description : {
                identifier: 'description',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客描述'
                }]
            }
        }
    });


</script>

</body>
</html>